package pattern.behavioral.chainofresponsibility;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: chaoyang.ren  
 * @date:Jun 6, 2017  
 * @time:11:34:06 AM   
 * @email:chaoyang.ren@foxmail.com  
 * @version: 1.0
 */
public class HandlerChain {
	private int index = 0;
	private List<NumberHandler> handlers = new ArrayList<NumberHandler>();
	
	public void addHandler(NumberHandler handler){
		handlers.add(handler);
	}
	
	public void handle(Number n){
		if(index < handlers.size()){
			handlers.get(index++).handleRequest(n, this);
		}
	}
}

